package cn.com.cfae.iras.doc.analyze.components;

import cn.com.cfae.iras.doc.analyze.pdf.training.PDFTrainingService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by zouxun on 2018/10/28
 */
@RestController
public class PDFTrainingController {
    private static Logger logger = LoggerFactory.getLogger(PDFTrainingController.class);

    @Autowired
    PDFTrainingService pdfTrainingService;

    @RequestMapping("/api/vi/training")
    public String training(){

        try{
            long t1 = System.currentTimeMillis();
            pdfTrainingService.PDFTraining();
            long t2  =System.currentTimeMillis();
            logger.info("耗时{}毫秒，PDF切词完成",(t2-t1));
        }catch (Exception e){
            logger.error(e.getMessage(),e);
        }

        return "Finish";
    }

    @RequestMapping("/api/vi/wordVectorModelTraining")
    public void wordVectorModelTraining(){

        try{
            logger.info("开始进行模型训练");
            long t1 = System.currentTimeMillis();
            pdfTrainingService.wordVectorModelTraining();
            long t2 = System.currentTimeMillis();
            logger.info("耗时{}毫秒，模型训练完成",(t2-t1));
        }catch (Exception e){
            logger.error(e.getMessage(),e);
        }

//        return "Finish";
    }

    @RequestMapping("/api/vi/similarityAnalyze")
    public Map<String,String> similarityAnalyze(@RequestBody Map params){
        Map<String,String> result = new HashMap<>();
        try{
            long t1 = System.currentTimeMillis();
            result = pdfTrainingService.similarityAnalyze(params);
            long t2 = System.currentTimeMillis();
            logger.info("相似度分析，耗时{}毫秒",(t2-t1));
            result.put("code","0");
        }catch (Exception e){
            logger.error(e.getMessage(),e);
        }
        return result;
    }
}
